package com.yuji.aacar.core.cores.event;

import org.greenrobot.eventbus.EventBus;

/**
 * <li>Date: 2017/3/13
 * <li>Description: 事件分发中心类
 */

public class CoreEventCenter {

    public static final int BUSSINESS_SERVICE_ERROR = 999999;
    public static final int NETWOR_NOT_CONNECT = 999998; //没有打开wifi或者4G

    //注册事件
    public static void register(Object context) {
        if (!EventBus.getDefault().isRegistered(context)) {
            EventBus.getDefault().register(context);
        }
    }
    //解除
    public static void unregister(Object context) {
        if (EventBus.getDefault().isRegistered(context)) {
            EventBus.getDefault().unregister(context);
        }
    }
    //发送消息
    public static void post(Object object) {
        EventBus.getDefault().post(object);
    }

    /**
     * 发送9999 网络失败请求
     * @param msg 发送的具体消息
     */
    public static void postMessage (int code, String msg) {
        CoreEventBusMessage message = new CoreEventBusMessage(String.valueOf(code), msg);
        post(message);
    }

    public static void postMessage (int code, int requestCode, String msg, String requestMethod) {
        CoreEventBusMessage message = new CoreEventBusMessage(String.valueOf(code), msg, requestCode, requestMethod);
        post(message);
    }

    public static void postObject (int messageCode , Object obj) {
        CoreEventBusMessage message = new CoreEventBusMessage();
        message.setMessageCode(String.valueOf(messageCode));
        message.setMessageObjects(obj);
        post(message);
    }

}
